package com.example.zuoye;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RegistActivity extends AppCompatActivity {
    public int Sign_RequestCode=1;
    private Button sign,login;
    private EditText name;
    private EditText psw;
    String name2,psw2;
    private TextView xinxi;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        sign=(Button)findViewById(R.id.sign);
        login=(Button)findViewById(R.id.login);
        name=(EditText) findViewById(R.id.name);
        psw=(EditText) findViewById(R.id.psw);

        sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(RegistActivity.this,SignActivity.class);
                startActivityForResult(intent,Sign_RequestCode);
            }
        });

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

               if(name2.equals(name.getText().toString())&&psw2.equals(psw.getText().toString()))
               {
                   Toast.makeText(RegistActivity.this,"登陆成功！",Toast.LENGTH_LONG).show();
                   /*Intent intent=new Intent();
                   intent.setClass(RegistActivity.this,MineActivity.class);
                  startActivity(intent);*/
               }
               else
               {
                   Toast.makeText(RegistActivity.this,"登录失败，请重新输入信息！",Toast.LENGTH_SHORT).show();
               }
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==Sign_RequestCode)
        {
            if(resultCode==RESULT_OK)
            {
                String name1=data.getStringExtra("name");
                String psw1=data.getStringExtra("psw");
                name.setText(name1);
                psw.setText(psw1);
                name2=name1;
                psw2=psw1;

                Intent intent=new Intent();
                intent.putExtra("name",name1);
                setResult(RESULT_OK,intent);

            }
        }
    }
}
